package com.youth.youthservice.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.youth.commonutils.BeanCopyUtils;
import com.youth.commonutils.R;
import com.youth.youthservice.entity.EduCourse;
import com.youth.youthservice.entity.EduTeacher;
import com.youth.youthservice.entity.vo.CourseVo.CourseInfoVo;
import com.youth.youthservice.service.EduCourseService;
import com.youth.youthservice.service.EduTeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@RequestMapping("/eduservice/indexfront")
//使用nginx是需要使用@CrossOrigin解决跨域问题的，现在使用gateway网关替代
@Api(description = "前台首页")
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;


    @ApiOperation("前台首页展示")
    @PostMapping("/TeacherAndCourse")
    public R getTeacherAndCourse() {
        IPage<EduCourse> page = new Page<>(1, 4);
        List<CourseInfoVo> courseVoList = BeanCopyUtils.copyBeanToList(courseService.page(page, null).getRecords(),
        CourseInfoVo.class);
        IPage<EduTeacher> page2 = new Page<>(1, 4);
        List<EduTeacher> teacherList = teacherService.page(page2, null).getRecords();
        return R.ok().data("courseList", courseVoList).data("teacherList", teacherList);
    }


}